home *** CD-ROM | disk | FTP | other *** search
/ Internet Surfer: Getting Started / Internet Surfer - Getting Started (Wayzata Technology)(7231)(1995).bin / pc / textfile / mac_faqs / puzz_faq / part15 < prev   
Encoding:
Text File  |  1995-01-01  |  49.1 KB  |  1,432 lines

  1. Xref: bloom-picayune.mit.edu rec.puzzles:18149 news.answers:3080
  2. Newsgroups: rec.puzzles,news.answers
  3. Path: bloom-picayune.mit.edu!enterpoop.mit.edu!snorkelwacker.mit.edu!usc!wupost!gumby!destroyer!uunet!questrel!chris
  4. From: uunet!questrel!chris (Chris Cole)
  5. Subject: rec.puzzles FAQ, part 15 of 15
  6. Message-ID: <puzzles-faq-15_717034101@questrel.com>
  7. Followup-To: rec.puzzles
  8. Summary: This posting contains a list of
  9.      Frequently Asked Questions (and their answers).
  10.      It should be read by anyone who wishes to
  11.      post to the rec.puzzles newsgroup.
  12. Sender: chris@questrel.com (Chris Cole)
  13. Reply-To: uunet!questrel!faql-comment
  14. Organization: Questrel, Inc.
  15. References: <puzzles-faq-1_717034101@questrel.com>
  16. Date: Mon, 21 Sep 1992 00:09:54 GMT
  17. Approved: news-answers-request@MIT.Edu
  18. Expires: Sat, 3 Apr 1993 00:08:21 GMT
  19. Lines: 1411
  20.  
  21. Archive-name: puzzles-faq/part15
  22. Last-modified: 1992/09/20
  23. Version: 3
  24.  
  25. ==> probability/coupon.s <==
  26. The problem is well known under the name of "COUPON COLLECTOR PROBLEM".
  27. The answer for n equally likely coupons is
  28. (1)        C(n)=n*H(n)    with H(n)=1+1/2+1/3+...+1/n.
  29. In the unequal probabilities case, with p_i the probability of coupon i,
  30. it becomes
  31. (2)        C(n)=int_0^infty [1-prod_{i=1}^n (1-exp(-p_i*t))] dt
  32. which reduces to (1) when p_i=1/n (An easy exercise).
  33. In the equal probabilities case  C(n)~n log(n). For a Zipf law,
  34. from (2), we have C(n)~n log^2(n).
  35.  
  36. A related problem is the "BIRTHDAY PARADOX" familiar to people
  37. interested in hashing algorithms: With a party of 24 persons,
  38. you are likely (i.e. with probability >50%) to find two with
  39. the same birthday. The non equiprobable case was solved by:
  40.     M. Klamkin and D. Newman, Extensions of the birthday
  41.     surprise, J. Comb. Th. 3 (1967), 279-282.
  42.  
  43. ==> probability/darts.p <==
  44. Peter throws two darts at a dartboard, aiming for the center.  The
  45. second dart lands farther from the center than the first.  If Peter now
  46. throws another dart at the board, aiming for the center, what is the
  47. probability that this third throw is also worse (i.e., farther from 
  48. the center) than his first?  Assume Peter's skilfulness is constant.
  49.  
  50. ==> probability/darts.s <==
  51. Since the three darts are thrown independently,
  52. they each have a 1/3 chance of being the best throw.  As long as the
  53. third dart is not the best throw, it will be worse than the first dart.
  54. Therefore the answer is 2/3.
  55.  
  56. Ranking the three darts' results from A (best) to C
  57. (worst), there are, a priori, six equiprobable outcomes.
  58.  
  59. possibility #    1    2    3    4    5    6
  60. 1st throw    A    A    B    B    C    C
  61. 2nd throw    B    C    A    C    A    B
  62. 3rd throw    C    B    C    A    B    A
  63.  
  64. The information from the first two throws shows us that the first
  65. throw will not be the worst, nor the second throw the best.  Thus
  66. possibilities 3, 5 and 6 are eliminated, leaving three equiprobable
  67. cases, 1, 2 and 4.  Of these, 1 and 2 have the third throw worse than
  68. the first; 4 does not.  Again the answer is 2/3.
  69.  
  70. ==> probability/flips.p <==
  71. Consider a run of coin tosses: HHTHTTHTTTHTTTTHHHTHHHHHTHTTHT
  72.  
  73. Define a success as a run of one H or T (as in THT or HTH).  Use two
  74. different methods of sampling.  The first method would consist of
  75. sampling the above data by taking 7 groups of three.  This translates
  76. into the following sequences HHT, HTT, HTT, THT, TTT, HHH, and THH.
  77. In this sample there was one success, THT.  The second method of
  78. sampling could be gotten by taking the groups in a serial sequence.
  79. Another way of explaining the method would be to take the tosses 1, 2,
  80. and 3 as the first set then tosses 2, 3, and 4 as the second set and
  81. so on to produce seven samples.  The samples would be HHT, HTH, THT,
  82. HTT TTH, THT, and HTT, thus giving two success, HTH and THT.  With
  83. these two methods what would be the expected value and the standard
  84. deviation for both methods?
  85.  
  86. ==> probability/flips.s <==
  87. Case 1:
  88.  
  89. Let us start with a simple case: Define success as T and consider
  90. sequences of length 1.  In this case, the two sampling techniques are
  91. equivalent.  Assuming that we are examining a truly random sequence of
  92. T and H.  Thus if n groups of single sequences are considered or a
  93. sequence of length n is considered we will have the following
  94. statistics on the number of successes:
  95.  
  96.     Mean = n/2,  and  standard deviation (sd) = square_root(n)/2
  97.  
  98.  
  99. Case 2:
  100.  
  101. Define success as HT or TH: Here the two sampling techniques need to
  102. be distinguished:
  103.  
  104. Sampling 1:  Take "n" groups of two:  Here probability of getting success in
  105. any group is 1/2 (TH and HT out of 4 possible cases). So the mean and the
  106. standard deviation is same as described in case 1.
  107.  
  108. Sampling 2: Generate a sequence of length "n".  It is easy to show
  109. that (n-1) samples are generated.  The number of successes in this
  110. sequence is same as the number of T to H and H to T transitions.  This
  111. problem is solved in John P. Robinson, Transition Count and Syndrome
  112. are Uncorrelated, IEEE Transactions on Information Theory, Jan 1988.
  113. I will just state the results:
  114.  
  115.   mean = (n-1)/2  and standard deviation = square_root(n-1)/2.
  116.  
  117. In fact, if you want "n" samples in this case you need to generate
  118. length (n+1) sequence.  Then the new mean and standard deviation are
  119. the same as described in Sampling 1. (replace n by n+1).  The
  120. advantage in this sampling (i.e., sampling 2) is that you need only
  121. generate a sequence length of (n+1) to obtain n sample points as
  122. opposed to 2n (n groups of 2) in Sampling 1.
  123.  
  124. OBSERVATION:  The statistics has not changed.
  125.  
  126.  
  127. Case 3:
  128.  
  129. Define success as THT and HTH.
  130.  
  131. Sampling 1: This is a simple situation.  Let us assume "n" samples
  132. need to be generated.  Therefore, "n" groups of three are generated.
  133. The probability of a group being successful is 1/4 (THT and HTH out of
  134. 8 cases).  Therefore mean and standard deviation are:
  135.  
  136.   mean= n/4 and sd= square_root(7n)/4
  137.  
  138. Sampling 2: This is not a simple situation.  Let us generate a random
  139. sequence of length "n".  There will be (n-2) samples in this case.
  140. Use an approach similar to that followed in the Jan 88 IEEE paper.  I
  141. will just state the results.  First we define a function or enumerator
  142. P(n,k) as the number of length "n" sequences that generate "k"
  143. successes.  For example,
  144.  
  145.      P(4,1)= 4  (HHTH, HTHH, TTHT, and THTT are 4 possible length 4 sequences).
  146.  
  147. I derived two generating functions g(x) and h(x) in order to enumerate
  148. P(n,k), they are compactly represented by the following matrix
  149. polynomial.
  150.  
  151.  
  152.             _    _      _     _           _   _
  153.        | g(x) |    | 1   1 | (n-3)   |  4  |
  154.        |      | =  |       |         |     | 
  155.        | h(x) |    | 1   x |         |2+2x |    
  156.            |_    _|    |_     _|         |_   _|
  157.  
  158. The above is expressed as matrix generating function.  It can be shown
  159. that P(n,k) is the coefficient of the x^k in the polynomial
  160. (g(x)+h(x)).
  161.  
  162. For example, if n=4 we get (g(x)+h(x)) from the matrix generating
  163. function as (10+4x+2x^2).  Clearly, P(4,1) (coefficient of x) is 4 and
  164. P(4,2)=2 ( There are two such sequences THTH, and HTHT).
  165.  
  166. We can show that
  167.  
  168.    mean(k) = (n-2)/4 and sd= square_root(5n-12)/4
  169.  
  170. If we want to compare Sampling 1 with Sampling 2 then in Sampling 2 we
  171. need to generate "n" samples. This can be done by using sequences of length
  172. (n+2).  Then our new statistics would be
  173.  
  174.    mean = n/4 (same as that in sampling 1)
  175.  
  176.    sd = square_root(5n-2)/4 (not the same as in sampling 1)
  177.  
  178.     sd in sampling 2 < sd in sampling 1.
  179.  
  180. This difference can be explained by the fact that in serial sampling
  181. there is dependence on the past state.  For example, if the past
  182. sample was TTT then we know that the next sample can't be a success.
  183. This was not the case in Case 1 or Case 2 (transition count). For
  184. example, in case 2 success was independent of previous sample. That is
  185. if my past sample was TT then my next sample can be TT or TH. The
  186. probability of success in Case 1 and Case 2 is not influenced by past
  187. history).
  188.  
  189. Similar approach can be followed for higher dimensional cases.
  190.  
  191. Here's a C program I had lying around that is relevant to the
  192. current discussion of coin-flipping.  The algorithm is N^3 (for N flips)
  193. but it could certainly be improved.  Compile with 
  194.  
  195.     cc -o flip flip.c -lm
  196.  
  197. -- Guy
  198.  
  199. _________________ Cut here ___________________
  200.  
  201. #include <stdio.h>
  202. #include <math.h>
  203.  
  204. char *progname;              /* Program name */
  205.  
  206. #define NOT(c) (('H' + 'T') - (c))
  207.  
  208.  
  209. /* flip.c -- a program to compute the expected waiting time for a sequence
  210.              of coin flips, or the probabilty that one sequence
  211.              of coin flips will occur before another.
  212.  
  213.     Guy Jacobson, 11/1/90
  214. */
  215.  
  216. main (ac, av) int ac; char **av;
  217. {
  218.     char *f1, *f2, *parseflips ();
  219.     double compute ();
  220.  
  221.     progname = av[0];
  222.  
  223.     if (ac == 2) {
  224.     f1 = parseflips (av[1]);
  225.     printf ("Expected number of flips until %s = %.1f\n",
  226.         f1, compute (f1, NULL));
  227.     }
  228.     else if (ac == 3) {
  229.  
  230.     f1 = parseflips (av[1]);
  231.     f2 = parseflips (av[2]);
  232.  
  233.     if (strcmp (f1, f2) == 0) {
  234.         printf ("Can't use the same flip sequence.\n");
  235.         exit (1);
  236.     }
  237.     printf ("Probability of flipping %s before %s = %.1f%%\n",
  238.         av[1], av[2], compute (f1, f2) * 100.0);
  239.     }
  240.     else
  241.       usage ();
  242. }
  243.  
  244. char *parseflips (s) char *s;
  245. {
  246.     char *f = s;
  247.  
  248.     while (*s)
  249.       if (*s == 'H' || *s == 'h')
  250.     *s++ = 'H';
  251.       else if (*s == 'T' || *s == 't')
  252.     *s++ = 'T';
  253.       else
  254.     usage ();
  255.  
  256.     return f;
  257. }
  258.  
  259. usage ()
  260. {
  261.     printf ("usage: %s {HT}^n\n", progname);
  262.     printf ("\tto get the expected waiting time, or\n");
  263.     printf ("usage: %s s1 s2\n\t(where s1, s2 in {HT}^n for some fixed n)\n",
  264.         progname);
  265.     printf ("\tto get the probability that s1 will occur before s2\n");
  266.     exit (1);
  267. }
  268.  
  269. /*
  270.   compute --  if f2 is non-null, compute the probability that flip
  271.               sequence f1 will occur before f2.  With null f2, compute
  272.           the expected waiting time until f1 is flipped
  273.  
  274.   technique:
  275.  
  276.     Build a DFA to recognize (H+T)*f1 [or (H+T)*(f1+f2) when f2
  277.     is non-null].  Randomly flipping coins is a Markov process on the
  278.     graph of this DFA.  We can solve for the probability that f1 precedes
  279.     f2 or the expected waiting time for f1 by setting up a linear system
  280.     of equations relating the values of these unknowns starting from each
  281.     state of the DFA.  Solve this linear system by Gaussian Elimination.
  282. */
  283.  
  284. typedef struct state {
  285.     char *s;                /* pointer to substring string matched */
  286.     int len;                /* length of substring matched */
  287.     int backup;             /* number of one of the two next states */
  288. } state;
  289.  
  290. double compute (f1, f2) char *f1, *f2;
  291. {
  292.     double solvex0 ();
  293.     int i, j, n1, n;
  294.  
  295.     state *dfa;
  296.     int nstates;
  297.  
  298.     char *malloc ();
  299.  
  300.     n = n1 = strlen (f1);
  301.     if (f2)
  302.     n += strlen (f2); /* n + 1 states in the DFA */
  303.  
  304.     dfa = (state *) malloc ((unsigned) ((n + 1) * sizeof (state)));
  305.  
  306.     if (!dfa) {
  307.     printf ("Ouch, out of memory!\n");
  308.     exit (1);
  309.     }
  310.  
  311.     /* set up the backbone of the DFA */
  312.  
  313.     for (i = 0; i <= n; i++) {
  314.     dfa[i].s = (i <= n1) ? f1 : f2;
  315.     dfa[i].len = (i <= n1) ? i : i - n1;
  316.     }
  317.  
  318.     /* for i not a final state, one next state of i is simply
  319.        i+1 (this corresponds to another matching character of dfs[i].s
  320.        The other next state (the backup state) is now computed.
  321.        It is the state whose substring matches the longest suffix
  322.        with the last character changed */      
  323.        
  324.     for (i = 0; i <= n; i++) {
  325.     dfa[i].backup = 0;
  326.     for (j = 1; j <= n; j++)
  327.       if ((dfa[j].len > dfa[dfa[i].backup].len)
  328.           && dfa[i].s[dfa[i].len] == NOT (dfa[j].s[dfa[j].len - 1])
  329.           && strncmp (dfa[j].s, dfa[i].s + dfa[i].len - dfa[j].len + 1,
  330.               dfa[j].len - 1) == 0)
  331.         dfa[i].backup = j;
  332.     }
  333.  
  334.     /* our dfa has n + 1 states, so build a system n + 1 equations
  335.        in n + 1 unknowns */
  336.  
  337.     eqsystem (n + 1);
  338.  
  339.     for (i = 0; i < n; i++)
  340.       if (i == n1)
  341.     equation (1.0, n1, 0.0, 0, 0.0, 0, -1.0);
  342.       else
  343.     equation (1.0, i, -0.5, i + 1, -0.5, dfa[i].backup, f2 ? 0.0 : -1.0);
  344.     equation (1.0, n, 0.0, 0, 0.0, 0, 0.0);
  345.  
  346.     free (dfa);
  347.  
  348.     return solvex0 ();
  349. }
  350.  
  351.  
  352. /* a simple gaussian elimination equation solver */
  353.  
  354. double *m, **M;
  355. int rank;
  356. int neq = 0;
  357.  
  358. /* create an n by n system of linear equations.  allocate space
  359.    for the matrix m, filled with zeroes and the dope vector M */
  360.  
  361. eqsystem (n) int n;
  362. {
  363.     char *calloc ();
  364.     int i;
  365.  
  366.     m = (double *) calloc (n * (n + 1), sizeof (double));
  367.     M = (double **) calloc (n, sizeof (double *));
  368.  
  369.     if (!m || !M) {
  370.     printf ("Ouch, out of memory!\n");
  371.     exit (1);
  372.     }
  373.  
  374.     for (i = 0; i < n; i++)
  375.       M[i] = &m[i * (n + 1)];
  376.     rank = n;
  377.     neq = 0;
  378. }
  379.  
  380. /* add a new equation a * x_na + b * x_nb + c * x_nc + d = 0.0
  381.    (note that na, nb, and nc are not necessarily all distinct.) */
  382.  
  383. equation (a, na, b, nb, c, nc, d) double a, b, c, d; int na, nb, nc;
  384. {
  385.     double *eq = M[neq++]; /* each row is an equation */
  386.     eq[na + 1] += a;
  387.     eq[nb + 1] += b;
  388.     eq[nc + 1] += c;
  389.     eq[0] = d;             /* column zero holds the constant term */
  390. }
  391.  
  392. /* solve for the value of variable x_0.  This will go nuts if
  393.    therer are errors (for example, if m is singular) */
  394.  
  395. double solvex0 ()
  396. {
  397.     register i, j, jmax, k;
  398.     register double  max, val;
  399.     register double *maxrow, *row;
  400.  
  401.  
  402.     for (i = rank; i > 0; --i) {      /* for each variable */
  403.  
  404.         /* find pivot element--largest value in ith column*/
  405.     max = 0.0;
  406.     for (j = 0; j < i; j++)
  407.         if (fabs (M[j][i]) > fabs (max)) {
  408.         max = M[j][i];
  409.         jmax = j;
  410.         }
  411.     /* swap pivot row with last row using dope vectors */
  412.     maxrow = M[jmax];
  413.     M[jmax] = M[i - 1];
  414.     M[i - 1] = maxrow;
  415.  
  416.     /* normalize pivot row */
  417.     max = 1.0 / max;
  418.     for (k = 0; k <= i; k++)
  419.       maxrow[k] *= max;
  420.  
  421.     /* now eliminate variable i by subtracting multiples of pivot row */
  422.     for (j = 0; j < i - 1; j++) {
  423.         row = M[j];
  424.         if (val = row[i])              /* if variable i is in this eq */
  425.         for (k = 0; k <= i; k++)
  426.           row[k] -= maxrow[k] * val;
  427.     }
  428.     }
  429.  
  430.     /* the value of x0 is now in constant column of first row
  431.        we only need x0, so no need to back-substitute */
  432.  
  433.     val = -M[0][0];
  434.  
  435.     free (M);
  436.     free (m);
  437.  
  438.     return val;
  439. }
  440.  
  441. _________________________________________________________________
  442. Guy Jacobson   (201) 582-6558              AT&T Bell Laboratories
  443.         uucp:  {att,ucbvax}!ulysses!guy       600 Mountain Avenue
  444.     internet:  guy@ulysses.att.com         Murray Hill NJ, 07974
  445.  
  446.  
  447.  
  448. ==> probability/flush.p <==
  449. Which set contains more flushes than the set of all possible hands?
  450. (1) Hands whose first card is an ace
  451. (2) Hands whose first card is the ace of spades
  452. (3) Hands with at least one ace
  453. (4) Hands with the ace of spades
  454.  
  455. ==> probability/flush.s <==
  456. An arbitrary hand can have two aces but a flush hand can't.  The average
  457. number of aces that appear in flush hands is the same as the average
  458. number of aces in arbitrary hands, but the aces are spread out more
  459. evenly for the flush hands, so set #3 contains a higher fraction of flushs.
  460.  
  461. Aces of spades, on the other hand, are spread out the same way over possible
  462. hands as they are over flush hands, since there is only one of them in the deck.
  463. Whether or not a hand is flush is based solely on a comparison between
  464. different cards in the hand, so looking at just one card is necessarily
  465. uninformative.  So the other sets contain the same fraction of flushes
  466. as the set of all possible hands.
  467.  
  468. ==> probability/hospital.p <==
  469. A town has two hospitals, one big and one small.  Every day the big
  470. hospital delivers 1000 babies and the small hospital delivers 100
  471. babies.  There's a 50/50 chance of male or female on each birth.
  472. Which hospital has a better chance of having the same number of boys
  473. as girls?
  474.  
  475. ==> probability/hospital.s <==
  476. If there are 2N babies born, then the probability of an even split is
  477.  
  478. (2N choose N) / (2 ** 2N) ,
  479.  
  480. where (2N choose N) = (2N)! / (N! * N!) .
  481.  
  482. This is a DECREASING function.
  483.  
  484. Think about it. If there are two babies born, then the probability of a
  485. split is 1/2 (just have the second baby be different from the first).
  486. With 2N babies, If there is a N,N-1 split in the first 2N-1, then there
  487. is a 1/2 chance of the last baby making it an even split.  Otherwise
  488. there can be no even split.  Therefore the probability is less than 1/2
  489. overall for an even split.
  490.  
  491. As N goes to infinity the probability of an even split approaches zero
  492. (although it is still the most likely event).
  493.  
  494. ==> probability/icos.p <==
  495. The "house" rolls two 20-sided dice and the "player" rolls one
  496. 20-sided die.  If the player rolls a number on his die between the
  497. two numbers the house rolled, then the player wins.  Otherwise, the
  498. house wins (including ties).  What are the probabilities of the player
  499. winning?
  500.  
  501. ==> probability/icos.s <==
  502. It is easily seen that if any two of the three dice agree that the
  503. house wins.  The probability that this does not happen is 19*18/(20*20).
  504. If the three numbers are different, the probability of winning is 1/3.
  505. So the chance of winning is 19*18/(20*20*3) = 3*19/200 = 57/200.
  506.  
  507. ==> probability/intervals.p <==
  508. Given two random points x and y on the interval 0..1, what is the average
  509. size of the smallest of the three resulting intervals?
  510.  
  511. ==> probability/intervals.s <==
  512. You could make a graph of the size of the
  513. smallest interval versus x and y.  We know that the height of the
  514. graph is 0 along all the edges of the unit square where it is defined
  515. and on the line x=y.  It achieves its maximum of 1/3 at (1/3,2/3) and
  516. (2/3,1/3).  Assuming the graph has no curves or bizzare jags, the
  517. volume under the graph must be 1/9 and so the average height must also
  518. be 1/9.
  519.  
  520. ==> probability/lights.p <==
  521. Waldo and Basil are exactly m blocks west and n blocks north from Central Park,
  522. and always go with the green light until they run out of options.  Assuming
  523. that the probability of the light being green is 1/2 in each direction and
  524. that if the light is green in one direction it is red in the other, find the
  525. expected number of red lights that Waldo and Basil will encounter.
  526.  
  527. ==> probability/lights.s <==
  528. Let E(m,n) be this number, and let (x)C(y) = x!/(y! (x-y)!).  A model
  529. for this problem is the following nxm grid:
  530.  
  531.      ^         B---+---+---+ ... +---+---+---+ (m,0)
  532.      |         |   |   |   |     |   |   |   |
  533.      N         +---+---+---+ ... +---+---+---+ (m,1)
  534. <--W + E-->    :   :   :   :     :   :   :   :
  535.      S         +---+---+---+ ... +---+---+---+ (m,n-1)
  536.      |         |   |   |   |     |   |   |   |
  537.      v         +---+---+---+ ... +---+---+---E (m,n)
  538.  
  539. where each + represents a traffic light.  We can consider each
  540. traffic light to be a direction pointer, with an equal chance of
  541. pointing either east or south.
  542.  
  543. IMHO, the best way to approach this problem is to ask:  what is the
  544. probability that edge-light (x,y) will be the first red edge-light
  545. that the pedestrian encounters?  This is easy to answer; since the
  546. only way to reach (x,y) is by going south x times and east y times,
  547. in any order, we see that there are (x+y)C(x) possible paths from
  548. (0,0) to (x,y).  Since each of these has probability (1/2)^(x+y+1)
  549. of occuring, we see that the the probability we are looking for is
  550. (1/2)^(x+y+1)*(x+y)C(x).  Multiplying this by the expected number
  551. of red lights that will be encountered from that point, (n-k+1)/2,
  552. we see that
  553.  
  554.             m-1
  555.            -----
  556.            \
  557. E(m,n) =    >    ( 1/2 )^(n+k+1) * (n+k)C(n) * (m-k+1)/2
  558.            /
  559.            -----
  560.             k=0
  561.  
  562.             n-1
  563.            -----
  564.            \
  565.       +     >    ( 1/2 )^(m+k+1) * (m+k)C(m) * (n-k+1)/2 .
  566.            /
  567.            -----
  568.             k=0
  569.  
  570.  
  571. Are we done?  No!  Putting on our Captain Clever Cap, we define
  572.  
  573.             n-1
  574.            -----
  575.            \
  576. f(m,n) =    >    ( 1/2 )^k * (m+k)C(m) * k 
  577.            /
  578.            -----
  579.             k=0
  580.  
  581. and
  582.  
  583.             n-1
  584.            -----
  585.            \
  586. g(m,n) =    >    ( 1/2 )^k * (m+k)C(m) .
  587.            /
  588.            -----
  589.             k=0
  590.  
  591. Now, we know that
  592.  
  593.              n
  594.            -----
  595.            \
  596. f(m,n)/2 =  >    ( 1/2 )^k * (m+k-1)C(m) * (k-1) 
  597.            /
  598.            -----
  599.             k=1
  600.  
  601. and since f(m,n)/2 = f(m,n) - f(m,n)/2, we get that
  602.  
  603.             n-1
  604.            -----
  605.            \
  606. f(m,n)/2 =  >    ( 1/2 )^k * ( (m+k)C(m) * k - (m+k-1)C(m) * (k-1) )
  607.            /
  608.            -----
  609.             k=1
  610.  
  611. - (1/2)^n * (m+n-1)C(m) * (n-1)
  612.  
  613.             n-2
  614.            -----
  615.            \
  616.  =          >    ( 1/2 )^(k+1) * (m+k)C(m) * (m+1)
  617.            /
  618.            -----
  619.             k=0
  620.  
  621. - (1/2)^n * (m+n-1)C(m) * (n-1)
  622.  
  623. = (m+1)/2 * (g(m,n) - (1/2)^(n-1)*(m+n-1)C(m)) - (1/2)^n*(m+n-1)C(m)*(n-1)
  624.  
  625. therefore
  626.  
  627. f(m,n) = (m+1) * g(m,n) - (n+m) * (1/2)^(n-1) * (m+n-1)C(m) .
  628.  
  629.  
  630. Now, E(m,n) = (n+1) * (1/2)^(m+2) * g(m,n) - (1/2)^(m+2) * f(m,n)
  631.  
  632. + (m+1) * (1/2)^(n+2) * g(n,m) - (1/2)^(n+2) * f(n,m)
  633.  
  634. = (m+n) * (1/2)^(n+m+1) * (m+n)C(m) + (m-n) * (1/2)^(n+2) * g(n,m)
  635.  
  636. + (n-m) * (1/2)^(m+2) * g(m,n) .
  637.  
  638.  
  639. Setting m=n in this formula, we see that
  640.  
  641.            E(n,n) = n * (1/2)^(2n) * (2n)C(n),
  642.  
  643. and applying Stirling's theorem we get the beautiful asymptotic formula
  644.  
  645.                   E(n,n) ~ sqrt(n/pi).
  646.  
  647. ==> probability/lottery.p <==
  648. There n tickets in the lottery, k winners and m allowing you to pick another
  649. ticket. The problem is to determine the probability of winning the lottery
  650. when you start by picking 1 (one) ticket.
  651.  
  652. A lottery has N balls in all, and you as a player can choose m numbers
  653. on each card, and the lottery authorities then choose n balls, define
  654. L(N,n,m,k) as the minimum number of cards you must purchase to ensure that
  655. at least one of your cards will have at least k numbers in common with the
  656. balls chosen in the lottery.
  657.  
  658. ==> probability/lottery.s <==
  659. This relates to the problem of rolling a random number
  660. from 1 to 17 given a 20 sided die.  You simply mark the numbers 18,
  661. 19, and 20 as "roll again".
  662.  
  663. The probability of winning is, of course, k/(n-m) as for every k cases
  664. in which you get x "draw again"'s before winning, you get n-m-k similar
  665. cases where you get x "draw again"'s before losing.  The example using
  666. dice makes it obvious, however.
  667.  
  668. L(N,k,n,k) >= Ceiling((N-choose-k)/(n-choose-k)*
  669.                    (n-1-choose-k-1)/(N-1-choose-k-1)*L(N-1,k-1,n-1,k-1))
  670.             = Ceiling(N/n*L(N-1,k-1,n-1,k-1))
  671.  
  672. The correct way to see this is as follows:  Suppose you have an
  673. (N,k,n,k) system of cards.  Look at all of the cards that contain the
  674. number 1.  They cover all ball sets that contain 1, and therefore these
  675. cards become an (N-1,k-1,n-1,k-1) covering upon deletion of the number
  676. 1.  Therefore the number 1 must appear at least L(N-1,k-1,n-1,k-1).
  677. The same is true of all of the other numbers.  There are N of them but
  678. n appear on each card.  Thus we obtain the bound.
  679.  
  680. ==> probability/particle.in.box.p <==
  681. A particle is bouncing randomly in a two-dimensional box.  How far does it
  682. travel between bounces, on avergae?
  683.  
  684. Suppose the particle is initially at some random position in the box and is
  685. traveling in a straight line in a random direction and rebounds normally
  686. at the edges.
  687.  
  688. ==> probability/particle.in.box.s <==
  689. Let theta be the angle of the point's initial vector.  After traveling a
  690. distance r, the point has moved r*cos(theta) horizontally and r*sin(theta)
  691. vertically, and thus has struck r*(sin(theta)+cos(theta))+O(1) walls.  Hence
  692. the average distance between walls will be 1/(sin(theta)+cos(theta)).  We now
  693. average this over all angles theta:
  694.     2/pi * intg from theta=0 to pi/2 (1/(sin(theta)+cos(theta))) dtheta
  695. which (in a computation which is left as an exercise) reduces to
  696.     2*sqrt(2)*ln(1+sqrt(2))/pi = 0.793515.
  697.  
  698. ==> probability/pi.p <==
  699. Are the digits of pi random (i.e., can you make money betting on them)?
  700.  
  701. ==> probability/pi.s <==
  702. No, the digits of pi are not truly random, therefore you can win money
  703. playing against a supercomputer that can calculate the digits of pi far
  704. beyond what we are currently capable of doing.  This computer selects a
  705. position in the decimal expansion of pi -- say, at 10^100.  Your job is
  706. to guess what the next digit or digit sequence is.  Specifically, you
  707. have one dollar to bet.  A bet on the next digit, if correct, returns
  708. 10 times the amount bet; a bet on the next two digits returns 100 times
  709. the amount bet, and so on.  (The dollar may be divided in any fashion,
  710. so we could bet 1/3 or 1/10000 of a dollar.)  You may place bets in any
  711. combination.  The computer will tell you the position number, let you
  712. examine the digits up to that point, and calculate statistics for you.
  713.  
  714. It is easy to set up strategies that might win, if the supercomputer
  715. doesn't know your strategy.  For example, "Always bet on 7" might win,
  716. if you are lucky.  Also, it is easy to set up bets that will always
  717. return a dollar.  For example, if you bet a penny on every two-digit
  718. sequence, you are sure to win back your dollar.  Also, there are
  719. strategies that might be winning, but we can't prove it.  For example,
  720. it may be that a certain sequence of digits never occurs in pi, but we
  721. have no way of proving this.
  722.  
  723. The problem is to find a strategy that you can prove will always win
  724. back more than a dollar.
  725.  
  726. The assumption that the position is beyond the reach of calculation
  727. means that we must rely on general facts we know about the sequence of
  728. digits of pi, which is practically nil.  But it is not completely nil,
  729. and the challenge is to find a strategy that will always win money.
  730.  
  731. A theorem of Mahler (1953) states that for all integers p, q > 1,
  732.  
  733.         -42
  734.   |pi - p/q| > q
  735.  
  736. This says that pi cannot have a rational approximation that is
  737. extremely tight.
  738.  
  739. Now suppose that the computer picks position N.  I know that the next
  740. 41 * N digits cannot be all zero.   For if they were, then the first N
  741. digits, treated as a fraction with denominator 10^N, satisfies:
  742.  
  743.   |pi - p / 10^N|  <  10^(-42 N)
  744.  
  745. which contradicts Mahler's theorem.
  746.  
  747. So, I split my dollar into 10^(41N) - 1 equal parts, and bet on each of
  748. the sequences of 41N digits, except the one with all zeroes.  One of
  749. the bets is sure to win, so my total profit is about 10(^-41N) of a
  750. dollar!
  751.  
  752. This strategy can be improved a number of ways, such as looking for
  753. other repeating patterns, or improvements to the bound of 42 -- but the
  754. earnings are so pathetic, it hardly seems worth the effort.
  755.  
  756. Are there other winning strategies, not based on Mahler's theorem?  I
  757. believe there are algorithms that generate 2N binary digits of pi,
  758. where the computations are separate for each block of N digits.  Maybe
  759. from something like this, we can find a simple subsequence of the
  760. binary digits of pi which is always zero, or which has some simple
  761. pattern.
  762.  
  763. ==> probability/random.walk.p <==
  764. Waldo has lost his car keys!  He's not using a very efficient search;
  765. in fact, he's doing a random walk.  He starts at 0, and moves 1 unit
  766. to the left or right, with equal probability.  On the next step, he
  767. moves 2 units to the left or right, again with equal probability.  For
  768. subsequent turns he follows the pattern 1, 2, 1, etc.
  769.  
  770. His keys, in truth, were right under his nose at point 0.  Assuming
  771. that he'll spot them the next time he sees them, what is the
  772. probability that poor Waldo will eventually return to 0?
  773.  
  774. ==> probability/random.walk.s <==
  775. I can show the probability that Waldo returns to 0 is 1.  Waldo's
  776. wanderings map to an integer grid in the plane as follows.  Let
  777. (X_t,Y_t) be the cumulative sums of the length 1 and length 2 steps
  778. respectively taken by Waldo through time t.  By looking only at even t,
  779. we get the ordinary random walk in the plane, which returns to the
  780. origin (0,0) with probability 1.  In fact, landing at (2n, n) for any n
  781. will land Waldo on top of his keys too.  There's no need to look at odd
  782. t.
  783.  
  784. Similar considerations apply for step sizes of arbitrary (fixed) size.
  785.  
  786. ==> probability/reactor.p <==
  787. There is a reactor in which a reaction is to take place. This reaction
  788. stops if an electron is present in the reactor. The reaction is started
  789. with 18 positrons; the idea being that one of these positrons would
  790. combine with any incoming electron (thus destroying both). Every second,
  791. exactly one particle enters the reactor. The probablity that this particle   
  792. is an electron is 0.49 and that it is a positron is 0.51.
  793.  
  794. What is the probablity that the reaction would go on for ever??
  795.  
  796. Note: Once the reaction stops, it cannot restart.
  797.  
  798. ==> probability/reactor.s <==
  799. Let P(n) be the probability that, starting with n positrons, the
  800. reaction goes on forever.  Clearly P'(n+1)=P'(0)*P'(n), where the
  801. ' indicates probabilistic complementation; also note that
  802. P'(n) = .51*P'(n+1) + .49*P'(n-1).  Hence we have that P(1)=(P'(0))^2
  803. and that P'(0) = .51*P'(1) ==> P'(0) equals 1 or 49/51.  We thus get
  804. that either P'(18) = 1 or (49/51)^19 ==> P(18) = 0 or 1 - (49/51)^19.
  805.  
  806. The answer is indeed the latter.  A standard result in random walks
  807. (which can be easily derived using Markov chains) yields that if p>1/2
  808. then the probability of reaching the absorbing state at +infinity
  809. as opposed to the absorbing state at -1 is 1-r^(-i), where r=p/(1-p)
  810. (p is the probability of moving from state n to state n-1, in our
  811. case .49) and i equals the starting location + 1.  Therefore we have
  812. that P(18) = 1-(.49/.51)^19.
  813.  
  814. ==> probability/roulette.p <==
  815. You are in a game of Russian roulette, but this time the gun (a 6
  816. shooter revolver) has three bullets _in_a_row_ in three of the
  817. chambers.  The barrel is spun only once.  Each player then points the
  818. gun at his (her) head and pulls the trigger.  If he (she) is still
  819. alive, the gun is passed to the other player who then points it at his
  820. (her) own head and pulls the trigger.  The game stops when one player
  821. dies.
  822.  
  823. Now to the point:  would you rather be first or second to shoot?
  824.  
  825. ==> probability/roulette.s <==
  826. All you need to consider are the six possible bullet configurations
  827.  
  828.     B B B E E E         -> player 1 dies
  829.     E B B B E E         -> player 2 dies
  830.     E E B B B E         -> player 1 dies
  831.     E E E B B B         -> player 2 dies
  832.     B E E E B B         -> player 1 dies
  833.     B B E E E B         -> player 1 dies
  834.  
  835. One therefore has a 2/3 probability of winning (and a 1/3 probability of
  836. dying) by shooting second.  I for one would prefer this option.
  837.  
  838. ==> probability/unfair.p <==
  839. Generate even odds from an unfair coin.  For example, if you
  840. thought a coin was biased toward heads, how could you get the
  841. equivalent of a fair coin with several tosses of the unfair coin?
  842.  
  843. ==> probability/unfair.s <==
  844. Toss twice.  If both tosses give the same result, repeat this process
  845. (throw out the two tosses and start again).  Otherwise, take the first
  846. of the two results.
  847.  
  848. ==> series/series.01.p <==
  849. M, N, B, D, P ?
  850.  
  851. ==> series/series.01.s <==
  852. T.  If you say the sounds these letters make out loud, you
  853. will see that the next letter is T.
  854.  
  855. ==> series/series.02.p <==
  856. H, H, L, B, B, C, N, O, F ?
  857.  
  858. ==> series/series.02.s <==
  859. Answer 1:  N, N, M, A  The symbols for the elements.
  860. Answer 2:  N, S, M, A  The names of the elements.
  861.  
  862. ==> series/series.03.p <==
  863. W, A, J, M, M, A, J?
  864.  
  865. ==> series/series.03.s <==
  866. J, V, H, T, P, T, F, P, B, L.  Presidents.
  867.  
  868. ==> series/series.03a.p <==
  869. G, J, T, J, J, J, A, M, W, J, J, Z, M, F, J, ?
  870.  
  871.  
  872. ==> series/series.03a.s <==
  873. G, J, T, J, J, J, A, M, W, J, J, Z, M, F, J, A.  Presidents' first names.
  874.  
  875. ==> series/series.03b.p <==
  876. A, J, B, C, G, T, C, V, J, T, D, F, K, B, H, ?
  877.  
  878.  
  879. ==> series/series.03b.s <==
  880. A, J, B, C, G, T, C, V, J, T, D, F, K, B, H, J.  Vice Presidents.
  881.  
  882. ==> series/series.03c.p <==
  883. M, A, M, D, E, L, R, H, ?
  884.  
  885.  
  886. ==> series/series.03c.s <==
  887. M, A, M, D, E, L, R, H, A.  Presidents' wives' first names.
  888.  
  889. ==> series/series.04.p <==
  890. A, E, H, I, K, L, ?
  891.  
  892. ==> series/series.04.s <==
  893. M, N, O, P, U, W.  Letters in the Hawaiian alphabet.
  894.  
  895. ==> series/series.05.p <==
  896. A B C D E F G H?
  897.  
  898. ==> series/series.05.s <==
  899. M.  The names of the cross-streets travelling west on (say) Commonwealth
  900. Avenue from Boston Garden: Arlington, Berkeley, Clarendon, Dartmouth,
  901. Exeter, Fairfield, Gloucester, Hereford, Massachusetts Ave.
  902.  
  903. ==> series/series.06.p <==
  904. Z, O, T, T, F, F, S, S, E, N?
  905.  
  906. ==> series/series.06.s <==
  907. T.  The name of the integers starting with zero.
  908.  
  909. ==> series/series.06a.p <==
  910. F, S, T, F, F, S, ?
  911.  
  912. ==> series/series.06a.s <==
  913. The words "first", "second", "third", etc.  The same as the previous from this
  914. point on.
  915.  
  916. ==> series/series.07.p <==
  917. 1, 1 1, 2 1, 1 2 1 1, ...
  918.  
  919. What is the pattern and asymptotics of this series?
  920.  
  921. ==> series/series.07.s <==
  922. Each line is derived from the last by the transformation (for example)
  923.  
  924. ... z z z x x y y y ... ->
  925. ... 3 z 2 x 3 y ...
  926.  
  927. John Horton Conway analyzed this in "The Weird and Wonderful Chemistry
  928. of Audioactive Decay" (T M Cover & B Gopinath (eds) OPEN PROBLEMS IN
  929. COMMUNICATION AND COMPUTATION, Springer-Verlag (1987)).  You can also
  930. find his most complete FRACTRAN paper in this collection.
  931.  
  932. First, he points out that under this sequence, you frequently get
  933. adjacent subsequences XY which cannot influence each other in any
  934. future derivation of the sequence rule.  The smallest such are
  935. called "atoms" or "elements".  As Conway claims to have proved,
  936. there are 92 atoms which show up eventually in every sequence, no
  937. matter what the starting value (besides <> and <22>), and always in
  938. the same non-zero limiting proportions.
  939.  
  940. Conway named them after some other list of 92 atoms.  As a puzzle,
  941. see if you can recreate the list from the following, in decreasing
  942. atomic number:
  943.  
  944. U Pa Th Ac Ra Fr Rn Ho.AT Po Bi Pm.PB Tl Hg Au Pt Ir Os Re Ge.Ca.W Ta
  945. HF.Pa.H.Ca.W Lu Yb Tm ER.Ca.Co HO.Pm Dy Tb Ho.GD EU.Ca.Co Sm PM.Ca.Zn
  946. Nd Pr Ce LA.H.Ca.Co Ba Cs Xe I Ho.TE Eu.Ca.SB Pm.SN In Cd Ag Pd Rh
  947. Ho.RU Eu.Ca.TC Mo Nb Er.ZR Y.H.Ca.Tc SR.U Rb Kr Br Se As GE.Na Ho.GA
  948. Eu.Ca.Ac.H.Ca.ZN Cu Ni Zn.CO Fe Mn CR.Si V Ti Sc Ho.Pa.H.CA.Co K Ar
  949. Cl S P Ho.SI Al Mg Pm.NA Ne F O N C B Be Ge.Ca.LI He Hf.Pa.H.Ca.Li
  950.  
  951. Uranium is 3, Protactinium is 13, etc.  Rn => Ho.AT means the following:
  952. Radon forms a string that consists of two atoms, Holmium on the left,
  953. and Astatine on the right.  I capitalize the symbol for At to remind
  954. you that Astatine, and not Holmium, is one less than Radon in atomic
  955. number.  As a check, against you or me making a mistake, Hf is 111xx,
  956. Nd is 111xxx, In and Ni are 111xxxxx, K is 111x, and H is 22.
  957.  
  958. Next see if you can at least prove that any atom other than Hydrogen,
  959. eventually (and always thereafter) forms strings containing all 92 atoms.
  960.  
  961. The grand Conway theorem here is that every string eventually forms (within
  962. a universal time limit) strings containing all the 92 atoms in certain
  963. specific non-zero limiting proportions, and that digits N greater than 3
  964. are eventually restricted to one of two atomic patterns (ie, abc...N and
  965. def...N for some {1,2,3} sequences abc... and def...), which Conway calls
  966. isotopes of Np and Pu.  (For N=2, these are He and Li), and that these
  967. transuranic atoms have a zero limiting proportion.
  968.  
  969. The longest lived exotic element is Methuselum (2233322211N) which takes
  970. about 25 applications to reduce to the periodic table.
  971.  
  972. -Matthew P Wiener (weemba@libra.wistar.upenn.edu)
  973.  
  974. Conway gives many results on the ultimate behavior of strings under
  975. this transformation: for example, taking the sequence derived from 1
  976. (or any other string except 2 2), the limit of the ratio of length of
  977. the (n+1)th term to the length of the nth term as n->infinity is a 
  978. fixed constant, namely
  979.  
  980.             1.30357726903429639125709911215255189073070250465940...
  981.  
  982. This number is from Ilan Vardi, "Computational Recreations in Mathematica",
  983. Addison Wesley 1991, page 13.
  984.  
  985. Another sequence that is related but not nearly as interesting is:
  986.  
  987. 1, 11, 21, 1112, 3112, 211213, 312213, 212223, 114213, 31121314, 41122314,
  988.     31221324, 21322314,
  989.  
  990. and 21322314 generates itself, so we have a cycle.
  991.  
  992. ==> series/series.08a.p <==
  993. G, L, M, B, C, L, M, C, F, S, ?
  994.  
  995. ==> series/series.08a.s <==
  996. Army officer ranks, descending.
  997.  
  998. ==> series/series.08b.p <==
  999. A, V, R, R, C, C, L, L, L, E, ?
  1000.  
  1001. ==> series/series.08b.s <==
  1002. Navy officer ranks, descending.
  1003.  
  1004. ==> series/series.09a.p <==
  1005. S, M, S, S, S, C, P, P, P, ?
  1006.  
  1007. ==> series/series.09a.s <==
  1008. Army non-comm ranks, descending.
  1009.  
  1010. ==> series/series.09b.p <==
  1011. M, S, C, P, P, P, S, S, S, ?
  1012.  
  1013. ==> series/series.09b.s <==
  1014. Navy non-comm ranks, descending.
  1015.  
  1016. ==> series/series.10.p <==
  1017. D, P, N, G, C, M, M, S, ?
  1018.  
  1019. ==> series/series.10.s <==
  1020. N, V, N, N, R.  States in Constitution ratification order.
  1021.  
  1022. ==> series/series.11.p <==
  1023. R O Y G B ?
  1024.  
  1025. ==> series/series.11.s <==
  1026. V.  Colors.
  1027.  
  1028. ==> series/series.12.p <==
  1029. A, T, G, C, L, ?
  1030.  
  1031. ==> series/series.12.s <==
  1032. V, L, S, S, C, A, P.  Zodiacal signs.
  1033.  
  1034. ==> series/series.13.p <==
  1035. M, V, E, M, J, S, ?
  1036.  
  1037. ==> series/series.13.s <==
  1038. U, N, P.  Names of the Planets.
  1039.  
  1040. ==> series/series.14.p <==
  1041. A, B, D, O, P, ?
  1042.  
  1043. ==> series/series.14.s <==
  1044. Q, R.  Only letters with an inside as printed. 
  1045.  
  1046. ==> series/series.14a.p <==
  1047. A, B, D, E, G, O, P, ?
  1048.  
  1049. ==> series/series.14a.s <==
  1050. Q.  Letters with cursive insides.
  1051.  
  1052. ==> series/series.15.p <==
  1053. A, E, F, H, I, ?
  1054.  
  1055. ==> series/series.15.s <==
  1056. L, M, N, O, S, U.  Letters whose English names start with vowels.
  1057.  
  1058. ==> series/series.16.p <==
  1059. A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, X, Y?
  1060.  
  1061. ==> series/series.16.s <==
  1062. Z.  Letters whose English names have one syllable.
  1063.  
  1064. ==> series/series.17.p <==
  1065. T, P, O, F, O, F, N, T, S, F, T, F, E, N, S, N?
  1066.  
  1067. ==> series/series.17.s <==
  1068. T, T, T, E, T, E.  Digits of Pi.
  1069.  
  1070. ==> series/series.18.p <==
  1071. 10, 11, 12, 13, 14, 15, 16, 17, 20, 22, 24, ___ , 100, 121, 10000
  1072.  
  1073. ==> series/series.18.s <==
  1074.  10, 11, 12, 13, 14, 15, 16, 17, 20, 22, 24, 31 , 100, 121, 10000
  1075.  
  1076. Sixteen in base n for n=16, 15, ..., 2.
  1077.  
  1078. ==> series/series.19.p <==
  1079. 1 01 01011 0101101011011 0101101011011010110101101101011011 etc.
  1080.  
  1081. Each string is formed from the previous string by substituting '01' for '1'
  1082. and '011' for '0' simultaneously at each occurance.
  1083. Notice that each string is an initial substring of the previous string so
  1084. that we may consider them all as initial substrings of an infinite string.
  1085. The puzzle then is, given n, determine if the nth digit is 0 or 1 without
  1086. having to construct all the previous digits.  That is, give a non-recursive
  1087. formula for the nth digit.
  1088.  
  1089. ==> series/series.19.s <==
  1090. Let G equal the limit string generated by the above process and define
  1091. the string F by
  1092.  
  1093. F[0] = "0",
  1094. F[n] = "1" if n = floor(phi*m) for some positive integer m,
  1095. F[n] = "0" if n = floor(phi^2*m) for some positive integer m,
  1096.  
  1097. where floor(x) is the greatest integer =< x and phi = (1 + \/5)/2;
  1098. I claim that F = G.
  1099.  
  1100.  
  1101. I will try to motivate my solution.  Let g[0]="0" and define g[n+1]
  1102. to be the string that results from replacing "0" in g[n] with "01"
  1103. and "1" with "011"; furthermore, let s(n) and t(n) be the number of
  1104. "0"'s and "1"'s in g[n], respectively.  Note that we have the
  1105. following recursive formulas : s(n+1) = s(n) + t(n) and t(n+1) =
  1106. s(n) + 2t(n).  I claim that s(n) = Fib(2n-1) and t(n) = Fib(2n),
  1107. where Fib(m) is the mth Fibonacci number (defined by Fib(-1) = 1,
  1108. Fib(0) = 0, Fib(n+1) = Fib(n) + Fib(n-1) for n>=0); this is easily
  1109. established by induction.  Now noting that Fib(2n)/Fib(2n-1) -> phi
  1110. as n -> infinity, we see that if the density of the "0"'s and "1"'s
  1111. exists, they must be be 1/phi^2 and 1/phi, respectively.  What is
  1112. the simplest generating sequence which has this property?  Answer:
  1113. the one given above.
  1114.  
  1115.  
  1116. Proof:  We start with
  1117.  
  1118. Beatty's Theorem: if a and b are positive irrational numbers such
  1119. that 1/a + 1/b = 1, then every positive integer has a representation
  1120. of the form floor(am) or floor(bm) (m a positive integer), and this
  1121. representation is unique.
  1122.  
  1123. This shows that F is well-defined.  I now claim that
  1124.  
  1125. Lemma: If S(n) and T(n) (yes, two more functions; apparently today's
  1126. the day that functions have their picnic) represent the number of
  1127. "0"'s and "1"'s in the initial string of F of length n, then S(n)
  1128. = ceil(n/phi^2) and T(n) = floor(n/phi) (ceil(x) is the smallest
  1129. integer >= x).
  1130.  
  1131. Proof of lemma: using the identity phi^2 = phi + 1 we see that S(n)
  1132. + T(n) = n, hence for a given n either S(n) = S(n-1) + 1 or T(n) =
  1133. T(n-1) + 1.  Now note that if F[n-1]="1" ==> n-1 = floor(phi*m) for
  1134. some positive integer m and since phi*m-1 < floor(phi*m) < phi*m ==>
  1135. m-1/phi < (n-1)/phi < m ==> T(n) = T(n-1) + 1.   To finish, note that
  1136. if F[n-1]="0" ==> n-1 = floor(phi^2*m) for some positive integer m
  1137. and since phi^2*m-1 < floor(phi^2*m) < phi^2*m ==> m-1/phi^2 <
  1138. (n-1)/phi^2 < m ==> S(n) = S(n-1) + 1.  Q.E.D.
  1139.  
  1140. I will now show that F is invariant under the operation of replacing
  1141. "0" with "01" and "1" with "011"; it will then follow that F=G.
  1142. Note that this is equivalent to showing that F[2S(n) + 3T(n)]
  1143. = "0", F[2S(n) + 3T(n) + 1] = "1", and that if n = [phi*m] for some
  1144. positive integer m, then F[2S(n) + 3T(n) + 2] = "1".  One could
  1145. waste hours trying to prove some fiendish identities; watch how
  1146. I sidestep this trap.  For the first part, note that by the above
  1147. lemma F[2S(n) + 3T(n)] = F[2*ceil(n/phi^2) + 3*floor(n/phi)] =
  1148. F[2n + floor(n/phi)] = F[2n + floor(n*phi-n)] = F[floor(phi*n+n)]
  1149. = F[floor(phi^2*n)] ==> F[2S(n) + 3T(n)] = "0".  For the second, it
  1150. is easy to see that since phi^2>2, if F[m]="0" ==> F[m]="1" hence
  1151. the first part implies the second part.  Finally, note that if n =
  1152. [phi*m] for some positive integer m, then F[2S(n) + 3T(n) + 3] =
  1153. F[2S(n+1) + 3T(n+1)] = "0", hence by the same reasoning as above
  1154. F[2S(n) + 3T(n) + 2] = "1".
  1155.  
  1156. Q.E.D.
  1157.  
  1158.     -- clong@remus.rutgers.edu (Chris Long)
  1159.  
  1160. ==> series/series.20.p <==
  1161. 1 2 5 16 64 312 1812 12288
  1162.  
  1163. ==> series/series.20.s <==
  1164. ANSWER: 95616
  1165.     The sum of factorial(k)*factorial(n-k) for k=0,...,n.
  1166.  
  1167. ==> series/series.21.p <==
  1168. 5, 6, 5, 6, 5, 5, 7, 5, ?
  1169.  
  1170. ==> series/series.21.s <==
  1171. The number of letters in the ordinal numbers.
  1172.  
  1173. First   5
  1174. Second  6
  1175. Third   5
  1176. Fourth  6
  1177. Fifth   5
  1178. Sixth   5
  1179. Seventh 7
  1180. Eighth  6
  1181. Ninth   5
  1182. etc.
  1183.  
  1184. ==> series/series.22.p <==
  1185. 3 1 1 0 3 7 5 5 2 ?
  1186.  
  1187. ==> series/series.22.s <==
  1188. ANSWER: 4
  1189.     The digits of pi expressed in base eight.
  1190.  
  1191. ==> series/series.23.p <==
  1192. 22 22 30 13 13 16 16 28 28 11 ?
  1193.  
  1194. ==> series/series.23.s <==
  1195. ANSWER: 15
  1196.     The birthdays of the Presidents of the United States.
  1197.  
  1198.  
  1199. ==> series/series.24.p <==
  1200. What is the next letter in the sequence: W, I, T, N, L, I, T?
  1201.  
  1202. ==> series/series.24.s <==
  1203. S.  First letters of words in question.
  1204.  
  1205. ==> series/series.25.p <==
  1206. 1 3 4 9 10 12 13 27 28 30 31 36 37 39 40 ?
  1207.  
  1208. ==> series/series.25.s <==
  1209. 1 3 4 9 10 12 13 27 28 30 31 36 37 39 40 ...
  1210. i in binary, treated as a base 3 number and converted to decimal.
  1211.  
  1212. ==> series/series.26.p <==
  1213. 1 3 2 6 7 5 4 12 13 15 14 10 11 9 8 24 25 27 26 ?
  1214.  
  1215. ==> series/series.26.s <==
  1216. 1 3 2 6 7 5 4 12 13 15 14 10 11 9 8 24 25 27 26 ...
  1217. Take i in binary, for each 1 bit (in i, not changed) flip the next bit.
  1218. This can also be phrased in reversing sequences of numbers.
  1219. More simply, just the integers in reflective-Gray-code order.
  1220.  
  1221. ==> series/series.27.p <==
  1222. 0 1 1 2 1 2 1 3 2 2 1 3 1 2 2 4 1 3 1 3 2 2 1 4 2 ?
  1223.  
  1224. ==> series/series.27.s <==
  1225. 0 1 1 2 1 2 1 3 2 2 1 3 1 2 2 4 1 3 1 3 2 2 1 4 2 ...
  1226. Number of factors in prime factorization of i.
  1227.  
  1228. ==> series/series.28.p <==
  1229. 0 2 3 4 5 5 7 6 6 7 11 7 13 9 8 8 17 8 19 9 10 13 23 9 10 ?
  1230.  
  1231. ==> series/series.28.s <==
  1232. 0 2 3 4 5 5 7 6 6 7 11 7 13 9 8 8 17 8 19 9 10 13 23 9 10 ...
  1233. Sum of factors in prime factorization of i.
  1234.  
  1235. ==> series/series.29.p <==
  1236. 1 1 2 1 2 2 3 1 2 2 3 2 3 3 4 1 2 2 3 2 3 3 4 2 3 3 4 3 4 ?
  1237.  
  1238. ==> series/series.29.s <==
  1239. 1 1 2 1 2 2 3 1 2 2 3 2 3 3 4 1 2 2 3 2 3 3 4 2 3 3 4 3 4 ...
  1240. The number of 1s in the binary expansion of n.
  1241.  
  1242. ==> series/series.30.p <==
  1243. I I T Y W I M W Y B M A D 
  1244.  
  1245. ==> series/series.30.s <==
  1246. ? (first letters of "If I tell you what it means will you buy me a drink?")
  1247.  
  1248. ==> series/series.31.p <==
  1249. 6 2 5 5 4 5 6 3 7 
  1250.  
  1251. ==> series/series.31.s <==
  1252. 6. The number of segments on a standard calculator display it takes
  1253. to represent the digits starting with 0.
  1254.   _       _   _       _   _   _   _   _
  1255.  | |   |  _|  _| |_| |_  |_    | |_| |_|
  1256.  |_|   | |_   _|   |  _| |_|   | |_|  _|
  1257.  
  1258. ==> series/series.32.p <==
  1259. 0 1 1 0 1 0 0 1 1 0 0 1 0 1 1 0 1
  1260.  
  1261. ==> series/series.32.s <==
  1262. 0 -> 1   01 -> 10   0110 -> 1001   01101001 ->  10010110
  1263. Recursively append the inverse.
  1264.  
  1265. This sequence is known as the Morse-Thue sequence.  It can be defined
  1266. non-recursively as the nth term is the mod 2 count of 1s in n written
  1267. in binary:
  1268.         0->0 1->1 10->1 11->0 100->1 101->0 110->0 111->1 etc. 
  1269.  
  1270. Reference:
  1271.     Dekking, et. al., "Folds! I,II,III"
  1272.     The Mathematical Intelligencer, v4,#3,#4,#4.
  1273.  
  1274. ==> series/series.33.p <==
  1275. 2 12 360 75600
  1276.  
  1277. ==> series/series.33.s <==
  1278. 2         = 2^1
  1279. 12        = 2^2 * 3^1
  1280. 360       = 2^3 * 3^2 * 5^1
  1281. 75600     = 2^4 * 3^3 * 5^2 * 7^1
  1282. 174636000 = 2^5 * 3^4 * 5^3 * 7^2 * 11^1
  1283.  
  1284. ==> series/series.34.p <==
  1285. 3 5 4 4 3 5 5 4 3
  1286.  
  1287. ==> series/series.34.s <==
  1288. The number of letters in the English words for the counting numbers.
  1289.  
  1290. ==> series/series.35.p <==
  1291. 1 2 3 2 1 2 3 4 2 1 2 3 4 2 2 3
  1292.  
  1293. ==> series/series.35.s <==
  1294. The number of letters in the Roman numeral representation of the numbers.
  1295.  
  1296. ==> trivia/area.codes.p <==
  1297. When looking at a map of the distribution of telephone area codes
  1298. for North America, it appears that they are randomly distributed.
  1299. I am doubtful that this is the case, however.  Does anyone know
  1300. how the area codes were/are chosen?
  1301.  
  1302. ==> trivia/area.codes.s <==
  1303. Originally, back in the middle 1950's when direct dialing of long
  1304. distance calls first became possible, the idea was to assign area codes
  1305. with the 'shortest' dialing time required to the larger cities.
  1306.  
  1307. Touch tone dialing was very rare. Most dialed calls were with 'rotary'
  1308. dials.  Area codes like 212, 213, 312 and 313 took very little time to
  1309. dial (while waiting for the dial to return to normal) as opposed, for
  1310. example, to 809, 908, 709, etc ...
  1311.  
  1312. So the 'quickest to dial' area codes were assigned to the places which
  1313. would probably receive the most direct dialed calls, i.e. New York City
  1314. got 212, Chicago got 312, Los Angeles got 213, etc ... Washington, DC got
  1315. 202, which is a little longer to dial than 212, but much shorter than
  1316. others.  
  1317.  
  1318. In order of size and estimated amount of telephone traffic, the numbers
  1319. got larger:  San Fransisco got 415, which is sort of in the middle, and
  1320. Miami got 305, etc.  At the other end of the spectrum came places like
  1321. Hawaii (it only got statehood as of about 1958) with 808,  Puerto Rico
  1322. with 809, Newfounland with 709, etc.
  1323.  
  1324. The original (and still in use until about 1993) plan is that area codes
  1325. have a certain construction to the numbers:
  1326.  
  1327. The first digit will be 2 through 9.
  1328. The second digit will always be 0 or 1.
  1329. The third digit will be 1 through 9.
  1330.  
  1331. Three digit numbers with two zeros will be special codes, ie. 700, 800 or
  1332. 900.  Three digit numbers with two ones are for special local codes,
  1333. i.e. 411 for local directory assistance, 611 for repairs, etc.
  1334.  
  1335. Three digit codes ending in '10', i.e. 410, 510, 610, 710, 810, 910 were
  1336. 'area codes' for the AT&T (and later on Western Union) TWX network. This
  1337. rule has been mostly abolished, however 610 is still Canadian TWX, and 
  1338. 910 is still used by Western Union TWX. Gradually the '10' codes are
  1339. being converted to regular area codes.
  1340.  
  1341. We are running out of possible combinations of numbers using the above
  1342. rules, and it is estimated that beginning in 1993-94, area codes will
  1343. begin looking like regular telephone prefix codes, with numbers other than
  1344. 0 or 1 as the second digit.
  1345.  
  1346. I hope this gives you a basic  idea. There were other rules at one time
  1347. such as not having an area code with zero in the second digit in the same
  1348. state as a code with one in the second digit, etc .. but after the initial
  1349. assignment of numbers back almost forty years ago, some of those rules
  1350. were dropped when it became apparent they were not flexible enough.
  1351.  
  1352.  
  1353. Patrick Townson
  1354. TELECOM Digest Moderator
  1355.  
  1356. -- 
  1357. Patrick Townson 
  1358.   patrick@chinet.chi.il.us / ptownson@eecs.nwu.edu / US Mail: 60690-1570 
  1359.   FIDO: 115/743 / AT&T Mail: 529-6378 (!ptownson) /  MCI Mail: 222-4956
  1360.  
  1361.  
  1362.  
  1363.  
  1364. ==> trivia/eskimo.snow.p <==
  1365. How many words do the Eskimo have for snow?
  1366.  
  1367. ==> trivia/eskimo.snow.s <==
  1368. Couple of weeks ago, someone named D.K. Holm in the Boston Phoenix came up
  1369. with the list, drawn from the Inupiat Eskimo Dictionary by Webster and
  1370. Zibell, and from Thibert's English-Eskimo Eskimo-English Dictionary.
  1371.  
  1372. The words may remind you of generated passwords.
  1373.  
  1374. Eskimo      English                 Eskimo       English
  1375. ---------------------------------+----------------------------
  1376. apun        snow                 |  pukak        sugar snow
  1377. apingaut    first snowfall       |  pokaktok     salt-like snow
  1378. aput        spread-out snow      |  miulik       sleet
  1379. kanik       frost                |  massak       snow mixed with water
  1380. kanigruak   frost on a           |  auksalak     melting snow
  1381.             living surface       |  aniuk        snow for melting
  1382. ayak        snow on clothes      |               into water
  1383. kannik      snowflake            |  akillukkak   soft snow
  1384. nutagak     powder snow          |  milik        very soft snow
  1385. aniu        packed snow          |  mitailak     soft snow covering an
  1386. aniuvak     snowbank             |               opening in an ice floe
  1387. natigvik    snowdrift            |  sillik       hard, crusty snow
  1388. kimaugruk   snowdrift that       |  kiksrukak    glazed snow in a thaw
  1389.             blocks something     |  mauya        snow that can be
  1390. perksertok  drifting snow        |               broken through
  1391. akelrorak   newly drifting snow  |  katiksunik   light snow
  1392. mavsa       snowdrift overhead   |  katiksugnik  light snow deep enough
  1393.             and about to fall    |               for walking
  1394. kaiyuglak   rippled surface      |  apuuak       snow patch
  1395.             of snow              |  sisuuk       avalanche
  1396.  
  1397.                     =*=                    
  1398.  
  1399. ==> trivia/federal.reserve.p <==
  1400. What is the pattern to this list:
  1401. Boston, MA
  1402. New York, NY
  1403. Philadelphia, PA
  1404. Cleveland, OH
  1405. Richmond, VA
  1406. Atlanta, GA
  1407. Chicago, IL
  1408. St. Louis, MO
  1409. Minneapolis, MN
  1410. Kansas City, MO
  1411. Dallas, TX
  1412. San Francisco, CA
  1413.  
  1414. ==> trivia/federal.reserve.s <==
  1415. Each of the cities is a location for a Federal Reserve.  The cities
  1416. are listed in alphabetical order based on the letter that represents each
  1417. city on a dollar bill. 
  1418.  
  1419. ==> trivia/jokes.self-referential.p <==
  1420. What are some self-referential jokes?
  1421.  
  1422. ==> trivia/jokes.self-referential.s <==
  1423. Q: What is alive, green, lives all over the world, and has seventeen legs?
  1424. A: Grass.  I lied about the legs.
  1425.  
  1426. The two rules for success are:
  1427. 1. Never tell them everything you know.
  1428.  
  1429. There are three kinds of people in the world: those who can count,
  1430. and those who cannot.
  1431.  
  1432.